home *** CD-ROM | disk | FTP | other *** search
/ Commodore Free 40 / Commodore_Free_Issue_40_2010_Commodore_Computer_Club.d64 / c 16 < prev    next >
Text File  |  2023-02-26  |  11KB  |  449 lines

  1.  
  2.  
  3. *************************************
  4.   COMMODORE FREE BASIC PROGRAMMING
  5.               CHALLENGE
  6.          Adapted C16 Version
  7.            By John Fielden
  8. *************************************
  9.  
  10. Listing of: asteroid16.prg
  11.  
  12. 10 REM *ASTEROIDS, NIGEL PARKER*
  13. (C64)
  14. 20 REM *C16 VERSION, JOHN FIELDEN*
  15. 30 DIMHI(15):DIMHI$(15)
  16. 40 HI(0)=90:HI$(0)="STAR
  17. MAN":HI(1)=50:HI$(1)="SUPER STAR"
  18. 50 HI(2)=40:HI$(2)="STAR
  19. MAN":HI(3)=30:HI$(3)="SUPER STAR"
  20. 60 F=100 :JF=0
  21. 70 A=0:B=A:C=A:I=A:S=A:F=40:A$=""
  22. 80
  23. PRINTCHR$(147);:POKE65305,0:POKE65301
  24. ,0:POKE1339,113
  25. 90 REM PRINTCHR$(5)
  26. 100 FORI=0TO23:PRINT:NEXTI
  27. 110
  28. B=1504:C=20:M=16:SC=3072:CO=2048:WI=4
  29. 0:HG=25
  30. 120
  31. B=SC+WI*INT(HG/2):C=INT(WI/2):BS=SC+W
  32. I*(HG-1)
  33. 130
  34. A=INT(40*RND(1)):IFRND(0)<.333THENA=0
  35. 140 Z=INT(40*RND(1))
  36. 150 IFA>0THENPOKE4012+A,46 :REM *DOT*
  37. 160
  38. IFRND(1)>.1THENP=INT(RND(1)*40):POKE4
  39. 012+Z,42 :REM *STAR*
  40. 170 GETA$ :REM(OWN LINE, MORE
  41. READABLE)
  42. 180 IFC<1THEN190:ELSEIFA$="Z"
  43. THENPOKEB+C,32:C=C-1
  44. 190 IFC>38THEN200:ELSEIFA$="X"
  45. THENPOKEB+C,32:C=C+1
  46. 200 POKEB+C,32 :REM *[SPACE]*
  47. 210 PRINT:F=F-1:IFF<1THEN270
  48. 220 IFPEEK(B+C)=42 THENJF=1:GOTO270
  49. 230 IFPEEK(B+C)=46 THENGOSUB350
  50. 240 POKEB+C,22 :REM * V *
  51. 250 S=S+1
  52. 260 GOTO130
  53. 270 PRINTCHR$(147);
  54. 280 PRINT"SORRY! ";
  55. 290 IFJF=1THEN PRINT"YOU HIT AN
  56. ASTEROID":ELSEPRINT" YOU RAN OUT OF
  57. FUEL!"
  58. 300 PRINT"YOU SCORED ";S;" POINTS"
  59. 310 PRINT
  60. 320 IFJF=1THEN PRINT" AND HAD ";F;"
  61. FUEL LEFT IN TANK"
  62. 330 PRINT
  63. 340 FORJA=0TO600:GETA$:NEXTJA:
  64. GOTO360
  65. 350
  66. FORI=0TO16:POKE65305,I:NEXTI:F=F+10:R
  67. ETURN
  68. 360 REM *ELITE PILOTS*
  69. 370 PRINT
  70. 380 FORJ=0TO10
  71. 390 IF S> HI(J) AND J<10THEN420
  72. 400 NEXTJ
  73. 410 GOTO500
  74. 420 PRINT"{SHIFT-+}down{SHIFT--} ELITE TABLE OF
  75. PILOTS"
  76. 430 INPUT"{SHIFT-+}down{SHIFT--} ENTER NAME ";N$
  77. 440 N$=LEFT$(N$,15)
  78. 450 FORX=JTO12
  79. 460 DV=HI(X):DV$=HI$(X)
  80. 470 HI(X)=S:HI$(X)=N$
  81. 480 S=DV:N$=DV$
  82. 490 NEXTX
  83. 500 REM *PILOT TABLE*
  84. 510 PRINT"{SHIFT-+}clr{SHIFT--} ASTEROID GAME, BY
  85. NIGEL PARKER."
  86. 520 PRINT" C16 CONVERSION, JOHN
  87. FIELDEN (2010)"
  88. 530 PRINT" WWW.COMMODOREFREE.COM
  89. ONLINE MAGAZINE!"
  90. 540 PRINT
  91. 550 PRINT" ELITE PILOTS"
  92. 560 PRINT"{SHIFT-+}down{SHIFT--}"
  93. 570 PRINT" NAME SCORE"
  94. 580 PRINT
  95. 590 FORT=0TO9:PRINTT+1;
  96. 600
  97. IFHI(T)=0THENHI$(T)="COMMODOREFREE"
  98. 610 PRINTHI$(T);"
  99. ":PRINT"{SHIFT-+}up{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}rig
  100. ht{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right
  101. {SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}
  102. right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}ri
  103. ght{SHIFT--}{SHIFT-+}right{SHIFT--}{SHIFT-+}right{SHIFT--}";HI(T)
  104. 620 NEXTT
  105. 630 PRINT"{SHIFT-+}down{SHIFT--} ANOTHER Y/N?"
  106. 640 GETKEYA$
  107. 650 IFA$<>"N"THEN60
  108.  
  109. 10 & 20 Always good to mark where it
  110. came from, and what it is.
  111.  
  112. Though we're learning REM statements
  113. slow the program down. These won't
  114. as they only get read once, And
  115. aren't in any repeated use loops
  116. etc.  So, the only question is the
  117. excess memory total they take up.
  118. Once you have the program in memory,
  119. type in this line:
  120.  
  121. PRINTFRE(X)
  122.  
  123. After playing the game a few times,
  124. upon exit. I got the answer: 58602
  125.  
  126. This is free memory in bytes. It is
  127. Yape, the plus4 emulator. The c16
  128. will have a smaller answer.
  129.  
  130. Type, followed by return key press.
  131.  
  132. 1
  133. 2
  134.  
  135. then retype printfre(x) line, or go
  136. up to it.  space out the answer
  137. beneath it and go to it, then press
  138. return key.  The answer I get is
  139. 59110. As I have no ability in maths
  140. I typed.
  141.  
  142. ?59110-58602 <return>
  143.  
  144. Gave the answer 508 followed by
  145. Ready.
  146.  
  147. Err, actually no!  I didn't think
  148. two little REM statements would take
  149. up so much room. There are several
  150. more statements in the listing,
  151. though I did keep these to a minimum
  152. for sake of speed. While on the
  153. subject of speed and saving memory;
  154. I've already renumbered the program
  155. lines to increment by 1. and lost a
  156. grand total of 9 bytes!  It seems
  157. the computer prefers to increment
  158. lines by 10.
  159.  
  160. 3 HI controls the score, while HI$
  161. is name that goes with it.
  162.  
  163. I put this into 15, so screen
  164. permitting, the high score table can
  165. go up to 14 (from 0).  The remainder
  166. is for calculation purposes.
  167. Reducing these to 12 doesn't seem to
  168. alter the free memory space.  And
  169. when I started adding the high score
  170. table, though I knew it took only
  171. three or four commands to sort.
  172. Which three were correct, and the
  173. right order was driving me up the
  174. wall.  More on that later.
  175.  
  176. Suffice to say I used a makeshift
  177. complex system of two tables, adding
  178. the new high score, and copying it
  179. over before putting it back again
  180. from that point.  Something still on
  181. file in case any-one is interested
  182. in a sort of 'long division' version
  183. of the sort technique.
  184.  
  185. 4 & 5  I put these in for debugging
  186. purposes, and are all but completely
  187. unnecessary, apart from aesthetics
  188. quality.  They give new pilots
  189. something EASY to aim at, at the
  190. start.
  191.  
  192. 6  Nothing is in the c64 version
  193. yet.  This is also added, as the
  194. game has been changed slightly.  The
  195. reason for this line is because it
  196. is extremely good programming to
  197. always set the variables, and even
  198. constants at the start of the
  199. program, and obviously at the value
  200. they start at.  For instance, it is
  201. no good thinking; this variable
  202. starts at 0 so I don't need to set
  203. it. ...
  204.  
  205. What if the program is modified
  206. later.  A good point is the high
  207. score table, which allows the user
  208. to play another game.  You can't
  209. just clear memory because you need
  210. the recorded scores in tact.  JF
  211. determines whether an asteroid has
  212. been hit, or whether the pilot
  213. wasn't able to refuel in time.  As
  214. now there are two ways to meet a
  215. demise.
  216.  
  217. 7.  You will know this from line 10
  218. of the original c64 version.  Added
  219. is F=40.
  220.  
  221. 8.  the chr$ code is the same.  The
  222. POKEs have different register
  223. values.  See orig. 90
  224.  
  225. 9 ...has vanished.  It took awhile,
  226. counting in values of 16 from the
  227. first grey point for POKE1339, 113
  228. is the best white colour.  Though
  229. things aren't always white in space.
  230. I had a chr$(5) for code white to
  231. overrule the prior grey.  But now it
  232. isn't needed.
  233.  
  234. 10 as line 100 of orig.
  235.  
  236. 11 has changed somewhat since line
  237. 110 of orig.  b and c are on the
  238. next line.  (This makes them defunct
  239. on line 7.  Neither is A needed as
  240. it is there on line 13.  delete
  241. them, change the =A to =0. then
  242. check fre(x)...I got 59140 with
  243. increments of ten!)
  244. 12 & 13 & 14  A lot of complicated
  245. calculations, best left for a
  246. professor of mathematics, which I am
  247. not.  But SC refers to the character
  248. set in POKE codes.  It shouldn't be
  249. SC really as this is reserved for
  250. Scores usually.  But it is part of a
  251. cheat sheet I was given, when my
  252. original attempt at converting the
  253. c64 code came back without drawing
  254. the ship, or referring to it at all.
  255. Just an endless scroll of asteroids
  256. and fuel dumps.  So I've kept this
  257. as is.
  258.  
  259. 15 p4012 is a place on screen, plus
  260. a determines where on that line the
  261. dot, i.e. "fuel dump" will go.
  262.  
  263. 16 Put a star along the line.  Not
  264. necessarily in a different place,
  265. but will take precedence over the
  266. dot if writing over it.
  267.  
  268. 17 look for a key press, but
  269. continue on your way; reading the
  270. following lines.  We can take the
  271. REM statement out as it says, the
  272. geta$ statement is better on its
  273. own, and the REM is counter
  274. productive to this end.  Changed
  275. from the orig. line 150.
  276.  
  277. 18 as rest of 150 in orig.  move the
  278. ship left upon keypess "Z"
  279.  
  280. 19 as orig. 160, except originally
  281. this was "M".  I changed it to "X"
  282. so that it is easier to navigate
  283. with one hand.  The other was
  284. dedicated to eating cola bottles
  285. throughout testing!  (Ahh! that
  286. Quinine hit, yum!!!).  moves ship to
  287. right on apt. key press. change if
  288. you wish.
  289.  
  290. 20 put a space in last ship
  291. position.  As orig. 170
  292.  
  293. 21 line feed, as 175 :F is Fuel.  As
  294. we go on our way, fuel is used.  If
  295. ship runs out it becomes lost in
  296. space.  Let's change "Super Star" at
  297. line 3 to "Will Robinson", and while
  298. we're at it line 5 to "Captain Kirk"
  299. or vice-versa.  Aye commander, sir!
  300.  
  301. EDITOR Hmmmm that Quinine hit is
  302. having strange effects on you
  303.  
  304. 22 Hit an asteroid, again goto27 to
  305. end game.  "It's worse than that
  306. he's dead Jim!"- orig. 180
  307.  
  308. 23 more fuel.  As orig. 190
  309.  
  310. 24 place ship.  As 195.  Another REM
  311. can be edited out.
  312.  
  313. 25 Increase score as much as fuel
  314. decreases. 1 per "scroll".
  315.  
  316. 26 As orig. line 300.  All the
  317. scroll did was push the characters
  318. printed one line up, though the ship
  319. is cleverly replaced, so it doesn't
  320. scroll up, but appears to stay where
  321. it is.  (though it would be more
  322. convincing if we could remove the
  323. flashing on and off all the time.)
  324. We go back for a new value of A.
  325. And start the whole process again
  326. from there.
  327.  
  328. 27 to 33 self explanatory Print
  329. statements,
  330.  
  331. 34 Any extra key presses after the
  332. crash became nullified with this
  333. statement, while the user is given
  334. chance to take in what has just
  335. happened.
  336.  
  337. 35 A subroutine, adding 10 units of
  338. fuel, upon hitting a dot.
  339.  
  340. 36  Only necessary while you
  341. familiarise yourself with program.
  342. Then you may delete this line,
  343. renumber1,1,1 and see if it runs
  344. faster.
  345.  
  346. 37 Add a line.
  347.  
  348. 38 start a new count
  349.  
  350. 39 if pilots score is greater than
  351. the one on the hi-table, at the
  352. point of where we are, and within
  353. range of shown table THEN leave this
  354. count.
  355.  
  356. 40 if not, see if next one is.
  357.  
  358. 41 if we haven't skipped this line,
  359. it means we're not good enough this
  360. score to go on the elite table.  So
  361. skip to the screen print of the
  362. pre-existing table.
  363.  
  364. 42 inform user, your in!
  365.  
  366. 43 get their name
  367.  
  368. 44 make sure it isn't a ridiculous
  369. length that won't fit and throw the
  370. whole thing up in the air.
  371.  
  372. 45 continue last count from where it
  373. left off
  374.  
  375. 46 make dummy variable for currently
  376. positioned table score
  377.  
  378. 47 put new score in table at this
  379. same position.
  380.  
  381. 48 place Dummy Variable as though it
  382. were score, ready to be put in at
  383. the next increment.
  384.  
  385. 49 increment by 1. i.e. add 1 to x,
  386. and go back to 45 to pass through
  387. loop again.
  388.  
  389. 50 actual table screen print, title.
  390.  
  391. 51 to 53 as it says,
  392. acknowledgements.
  393.  
  394. 54 skip a line
  395.  
  396. 55 spaces in relevant place haven't
  397. been listed.  (11)
  398.  
  399. 56 could blank this line, and put
  400. cursor down in next line for same
  401. effect.
  402.  
  403. 57 more spaces missed.  After NAME
  404. (17)
  405.  
  406. 58 miss a line for aesthetics.
  407.  
  408. 59 start a new count, print the
  409. count as placement, adding 1 because
  410. who was ever the nought best at
  411. anything?  That's why I like
  412. computers, their in a world of their
  413. own!  The semi colon ";" (or "dot
  414. uh, comma!" as Dad would call it
  415. constantly when we typed in Star
  416. Trader from Melbourne House' Games
  417. Book, tells the computer to keep the
  418. cursor there, on that line.
  419.  
  420. 60 If score at current count hasn't
  421. been occupied then advertise this
  422. excellent magazine!
  423.  
  424. 61 put the score in the appropriate
  425. place on the same line as current
  426. count.
  427.  
  428. 62 get info. For next count.
  429.  
  430. 63 wait for next challenge, end if
  431. told no.
  432.  
  433. 64 wait for key to be pressed.
  434.  
  435. 65 if not N, assume another game is
  436. requested. if it is No, game comes
  437. to natural END, without need for
  438. statement because there is no sub
  439. routine (yet) following it.
  440.  
  441. NOTE: I've included listing with
  442. increments of 10, so you can easily
  443. alter the program accordingly, and
  444. perhaps make your own changes.  The
  445. conversion is easy, put a 0 on the
  446. end of each line number so 1 becomes
  447. 10 etc
  448.  
  449. =====================================